package com.zretc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zretc.dao.OrderMapper;
import com.zretc.entity.Order;
import com.zretc.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Map<String,Object>> getOrder(String accountId)
    {
        return orderMapper.findOrder(accountId);
    }

    @Override
    public PageInfo<Order> getOrderDetail(Map<String, String> params) {
        int pageNum=Integer.parseInt(params.get("pageNum"));
        int pageSize=Integer.parseInt(params.get("pageSize"));
        PageHelper.startPage(pageNum,pageSize);

        String accountName = params.get("accountName");
        String isDelete = params.get("isDelete");
        String adminId = params.get("adminId");
        Map<String,String> map=new HashMap<>();
        if (accountName==null||"".equals(accountName)){
            map.put("accountName",null);
        }else{
            map.put("accountName","%" +accountName+"%");
        }
        if ("3".equals(isDelete)||isDelete==null){
            map.put("isDelete",null);
        }else {
            map.put("isDelete",isDelete);
        }
        if (adminId==null||"".equals(adminId)){
            map.put("adminId",null);
        }else{
            map.put("adminId",adminId);
        }

        List<Order> list = orderMapper.findOrderDetail(map);

        PageInfo<Order> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public boolean delOrderByOrderId(String orderId) {
        return orderMapper.delOrderByOrderId(orderId);
    }

    @Override
    public boolean updateStateByOrderId(String orderId, int isDelete) {
        return orderMapper.updateStateByOrderId(orderId,isDelete);
    }
}
